﻿var 
	less = require('gulp-less'),
	browserSync = require('browser-sync'),
	fileinclude = require('gulp-file-include');

const gulp = require('gulp');
const { src, dest ,watch, series,parallel,task } = gulp


function less_build(cb) {
	src('less/*.less')
	.pipe(less())
	.pipe(dest('css/'));
	cb()
}
task(less_build)

function html_build(cb) {
	src('src/views/report/*.html')
	.pipe(fileinclude({
		prefix: '@@',
		basepath: 'src/includes'
	}))
	.pipe(gulp.dest('./static'));
	cb()
}

function watch_tsk(cb) {
	watch('less/*.less', less_build);
	cb()
}

function browser_sync(cb) {
	browserSync.init({
		server: {
			baseDir: "./"
		},
		port:2333,
		ui: {
			port: 2111
		}
    });
    //监听任何文件变化，实时刷新页面
	watch(["./css/**/*.*","*.html","./plugins/**/*.*"], function(cb2){
		browserSync.reload()
		cb2()
	});
	cb()
}

exports.default = series(watch_tsk, browser_sync, less_build)